package com.fsnbigdata.domain;

import io.springlets.format.EntityFormat;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Version;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.NumberFormat;
import org.springframework.roo.addon.javabean.annotations.RooEquals;
import org.springframework.roo.addon.javabean.annotations.RooJavaBean;
import org.springframework.roo.addon.javabean.annotations.RooToString;
import org.springframework.roo.addon.jpa.annotations.entity.JpaRelationType;
import org.springframework.roo.addon.jpa.annotations.entity.RooJpaEntity;
import org.springframework.roo.addon.jpa.annotations.entity.RooJpaRelation;
import org.springframework.util.Assert;

/**
 * = ParkDistrictOrganism
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJavaBean
@RooToString
@RooJpaEntity
@RooEquals(isJpaEntity = true)
@Entity
@EntityFormat
public class ParkDistrictOrganism {

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    @Version
    private Integer version;

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    @ManyToOne(fetch = FetchType.EAGER)
    @EntityFormat
    private ParkDistrict parkDistrict;

    /**
     * 名称
     */
    @NotNull
    @Length(min = 1, max = 255,message ="名称信息内容长度必须在1-255个字符之间")
    private String name;

    /**
     * 拉丁名称
     */
    @Length(min = 0, max = 255,message ="拉丁名称信息内容长度必须在0-255个字符之间")
    private String latinName;

    /**
     * 照片
     */
    private String image;

    /**
     * 生物id
     */
    @NumberFormat
    private Long organismId;

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    @OneToMany(cascade = { javax.persistence.CascadeType.ALL }, fetch = FetchType.EAGER, mappedBy = "parkDistrictOrganism", orphanRemoval = true)
    @RooJpaRelation(type = JpaRelationType.COMPOSITION)
    @OrderBy("id")
    private Set<ParkDistrictOrganismImage> images = new HashSet<ParkDistrictOrganismImage>();

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE = "The given Iterable of items to add can't be null!";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE = "The given Iterable of items to add can't be null!";

    /**
     * This `equals` implementation is specific for JPA entities and uses
     * the entity identifier for it, following the article in
     * https://vladmihalcea.com/2016/06/06/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
     *
     * @param obj
     * @return Boolean
     */
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        // instanceof is false if the instance is null
        if (!(obj instanceof ParkDistrictOrganism)) {
            return false;
        }
        return getId() != null && Objects.equals(getId(), ((ParkDistrictOrganism) obj).getId());
    }

    /**
     * This `hashCode` implementation is specific for JPA entities and uses a fixed `int` value to be able
     * to identify the entity in collections after a new id is assigned to the entity, following the article in
     * https://vladmihalcea.com/2016/06/06/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
     *
     * @return Integer
     */
    public int hashCode() {
        return 31;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Long
     */
    public Long getId() {
        return this.id;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param id
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Integer
     */
    public Integer getVersion() {
        return this.version;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param version
     */
    public void setVersion(Integer version) {
        this.version = version;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return ParkDistrict
     */
    public ParkDistrict getParkDistrict() {
        return this.parkDistrict;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param parkDistrict
     */
    public void setParkDistrict(ParkDistrict parkDistrict) {
        this.parkDistrict = parkDistrict;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getName() {
        return this.name;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getLatinName() {
        return this.latinName;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param latinName
     */
    public void setLatinName(String latinName) {
        this.latinName = latinName;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getImage() {
        return this.image;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param image
     */
    public void setImage(String image) {
        this.image = image;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Long
     */
    public Long getOrganismId() {
        return this.organismId;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param organismId
     */
    public void setOrganismId(Long organismId) {
        this.organismId = organismId;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Set
     */
    public Set<ParkDistrictOrganismImage> getImages() {
        return this.images;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param images
     */
    public void setImages(Set<ParkDistrictOrganismImage> images) {
        this.images = images;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String toString() {
        return "ParkDistrictOrganism {" + "id='" + id + '\'' + ", version='" + version + '\'' + ", name='" + name + '\'' + ", latinName='" + latinName + '\'' + ", image='" + image + '\'' + ", organismId='" + organismId + '\'' + ", ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE='" + ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE + '\'' + ", ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE='" + ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE + '\'' + "}" + super.toString();
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param imagesToAdd
     */
    public void addToImages(Iterable<ParkDistrictOrganismImage> imagesToAdd) {
        Assert.notNull(imagesToAdd, ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE);
        for (ParkDistrictOrganismImage item : imagesToAdd) {
            this.images.add(item);
            item.setParkDistrictOrganism(this);
        }
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param imagesToRemove
     */
    public void removeFromImages(Iterable<ParkDistrictOrganismImage> imagesToRemove) {
        Assert.notNull(imagesToRemove, ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE);
        for (ParkDistrictOrganismImage item : imagesToRemove) {
            this.images.remove(item);
            item.setParkDistrictOrganism(null);
        }
    }
}
